
/*#include<bits/stdc++.h>

using namespace std;

struct IINNTT{
	int d,v,a;
};

double tim;
int s;
int ds;
int ans;
int ans1;
IINNTT a[100020];
int b[100020];
int bf[100020];
int fuck(int x,int n){
	int l = 1;
	int r = n;
	int ret;
	
	while(l <= r){
		int mid = (l + r) / 2;
		if(b[mid] > x){
			r = mid - 1;
			ret = mid;
		}else if(b[mid] <= x){
			l = mid + 1;
		}
	}

	return ret;
}

int fuck1(int x,int n){
	int l = 1;
	int r = n;
	
	int ret = n+11;
	while(l <= r){
		int mid = (l + r) / 2;
		if(b[mid] == x) {
			ret = mid;
			break;
		}else if(b[mid] > x){
			 r = mid - 1;
		}else {
			l = mid + 1; 
		}
		
			
	}
	return ret;
	
}
int main(){
	
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	
	int t;
	cin>>t;
	while(t--){
		int n,m,l,v;
		cin>>n>>m>>l>>v;
		ans = 0;
		ans1 = 0;
		for(int i = 1;i <= m;i++){
			bf[i] = 0;
		}
		for(int i = 1;i <= n;i++){
			
			cin>>a[i].d;
			cin>>a[i].v;
			cin>>a[i].a;
		}
		for(int i = 1;i <= m;i++){
			cin>>b[i];
		}
		b[m + 1] = 10000000;
		for(int i = 1;i <= n;i++){
			if(a[i].v >= v){
				ans++;
				int idx = min(fuck(a[i].d,m),fuck1(a[i].d,m));
				bf[idx]=1;
			}
		}
		for(int i = 1;i <= m;i++){
			if(bf[i]) ans1++;
		}
		cout<<ans<<" "<<ans1<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
*/
#include<bits/stdc++.h>

using namespace std;

struct IINNTT{
	int d,v,a;
};

double tim;
int s;
int ds;
int ans;
int ans1;
IINNTT a[100020];
int b[100020];
int bf[100020];

int main(){
	
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	
	int t;
	cin>>t;
	while(t--){
		int n,m,l,v;
		cin>>n;
		cin>>m;
		cin>>l;
		cin>>v;
		ans = 0;
		ans1 = 0;
		for(int i = 1;i <= m;i++){
			bf[i] = 0;
		}
		for(int i = 1;i <= n;i++){
			
			cin>>a[i].d;
			cin>>a[i].v;
			cin>>a[i].a;
		}
		for(int i = 1;i <= m;i++){
			cin>>b[i];
		}
		for(int i = 1;i <= n;i++){
			if(a[i].v >= v){
				ans++;
				for(int j = 1;j <= m;j++){
					if(b[j] >= a[i].v){
						 bf[j]=1;break;
					}
				}
			}
		}
		for(int i = 1;i <= m;i++){
			if(bf[i]) ans1++;
		}
		cout<<ans<<" "<<m - ans1<<endl;
	}
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
